package com.exam.online.system.util;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yuzhen
 * @date 2019/4/13
 */
public class PageModel<T> {

    /**
     * 总量
     */
    private int totalRecords = 0;
    /**
     * 当前页
     */
    private int pageNo = 0;
    /**
     * 总页数
     */
    private int totalPages = 0;
    /**
     * 页容量
     */
    private int pageSize = 0;
    /**
     * 具象数据
     */
    private List<T> datas = new ArrayList<>();

    public int getTotalRecords() {
        return totalRecords;
    }

    public void setTotalRecords(int totalRecords) {
        this.totalRecords = totalRecords;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getDatas() {
        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }

    public static <T> PageModel<T> emptyPage() {
        PageModel<T> emptyPage = new PageModel<>();
        emptyPage.setPageNo(0);
        emptyPage.setPageSize(0);
        emptyPage.setTotalPages(0);
        emptyPage.setTotalRecords(0);
        return emptyPage;
    }

    public static <T> PageModel<T> customPage(int pageNo, int pageSize, int totalPages, int totalRecords) {
        PageModel<T> customPage = new PageModel<>();
        customPage.setPageNo(pageNo);
        customPage.setPageSize(pageSize);
        customPage.setTotalPages(totalPages);
        customPage.setTotalRecords(totalRecords);
        return customPage;
    }

}
